<template>
  <!-- 企业信息管理 -->
  <div class="deptInfopoint">
    <basic-container>
      <avue-crud :option="option"
                 :table-loading="loading"
                 :data="data"
                 :page.sync="page"
                 ref="crud"
                 @row-del="rowDel"
                 v-model="form"
                 :permission="permissionList"
                 @row-update="rowUpdate"
                 @row-save="rowSave"
                 :before-open="beforeOpen"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 @selection-change="selectionChange"
                 @current-change="currentChange"
                 @size-change="sizeChange"
                 @refresh-change="refreshChange"
                 :upload-preview="uploadPreview"
                 :upload-error="uploadError"
                 :upload-delete="uploadDelete"
                 :upload-before="uploadBefore"
                 :upload-after="uploadAfter"
                 @on-load="onLoad">
        <template slot="menuLeft">
          <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.dept_info_delete" @click="handleDelete">删 除</el-button>
        </template>

        <!-- 地图表单自定义 -->
        <template slot="deptMapForm">
          <div v-if="deptShowMap">
            <baidu-map class="map" :center="center" :zoom="zoom" @ready="deptInfoHandler">
              <el-input placeholder="关键词查询" v-model="searchWord" style="position:absolute;top:10px;left:10px;width:180px;">
                <template slot="append">
                  <el-button icon="el-icon-search" id="citySearch"></el-button>
                </template>
              </el-input>

              <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
              <bm-marker :position="mapPosition" :dragging="true"></bm-marker>
            </baidu-map>
          </div>
        </template>

      </avue-crud>

      <el-dialog title="图片预览" append-to-body :visible.sync="localPicBox" width="50%">
        <el-image :key="localPicUrl" :src="localPicUrl" lazy></el-image>
      </el-dialog>

    </basic-container>
  </div>
</template>

<script>
  import {getList, remove, update, add, getDeptInfo} from "@/api/basedata/dept_info";
  import {getToken} from "@/util/auth";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {
          qypmt: [],
          qyyyzz: [],
          qyzp: []
        },
        localPicUrl: "",
        localPicBox: false,
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height: 'auto',
          calcHeight: 30,
          dialogWidth: 950,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          excelBtn: true,
          dialogClickModal: false,
          column: [
            {
              label: "统一社会信用代码",
              prop: "tyshxydm",
              align: "center",
              search: true,
              display: false
            },
            {
              label: "主要负责人",
              prop: "zyfzr",
              align: "center",
              search: true,
              display: false
            },
            {
              label: "企业名称",
              prop: "qymc",
              align: "center",
              search: true,
              display: false
            }
          ],
          group: [
            {
              label: '企业信息',
              prop: 'deptInfo',
              icon: 'el-icon-s-order',
              column: [
                {
                  label: "企业名称",
                  prop: "qymc",
                  align: "center",
                  span: 24,
                  row: true,
                  rules: [{
                    required: true,
                    message: "请输入企业名称",
                    trigger: "click"
                  }]
                }, {
                  label: "企业ID",
                  prop: "qyid",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入企业ID",
                    trigger: "blur"
                  }],
                }, {
                  label: "统一社会信用代码",
                  prop: "tyshxydm",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入统一社会信用代码",
                    trigger: "blur"
                  }],
                },
                {
                  label: '行政区划',
                  prop: 'szs1',
                  align: "center",
                  type: 'select',
                  cascaderIndex:0,
                  props: {
                    label: 'name',
                    value: 'code'
                  },
                  cascaderItem: ['szs2', 'szx', 'szxz'],
                  dicUrl: "/api/deptInfoManage/bladeDeptInfo/getXzqhList?code={{key}}",
                  span: 6,
                  rules: [{
                    required: true,
                    message: "请选择省份",
                    trigger: "blur"
                  }]
                },
                {
                  label: '',
                  prop: 'szs2',
                  align: "center",
                  type: 'select',
                  cascaderIndex:0,
                  props: {
                    label: 'name',
                    value: 'code'
                  },
                  dicFlag: false,
                  dicUrl: "/api/deptInfoManage/bladeDeptInfo/getXzqhList?code={{key}}",
                  span: 6,
                  rules: [{
                    required: true,
                    message: "请选择市级",
                    trigger: "blur"
                  }]
                },
                {
                  label: '',
                  prop: 'szx',
                  align: "center",
                  type: 'select',
                  cascaderIndex:0,
                  props: {
                    label: 'name',
                    value: 'code'
                  },
                  dicFlag: false,
                  dicUrl: "/api/deptInfoManage/bladeDeptInfo/getXzqhList?code={{key}}",
                  span: 6,
                  rules: [{
                    required: true,
                    message: "请选择区县",
                    trigger: "blur"
                  }]
                },
                {
                  label: '',
                  prop: 'szxz',
                  align: "center",
                  type: 'select',
                  cascaderIndex:0,
                  props: {
                    label: 'name',
                    value: 'code'
                  },
                  dicFlag: false,
                  dicUrl: "/api/deptInfoManage/bladeDeptInfo/getXzqhList?code={{key}}",
                  span: 6,
                  rules: [{
                    required: false,
                    message: "请选择乡镇",
                    trigger: "blur"
                  }]
                },
                {
                  label: "所在村（社区）",
                  prop: "szc",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入所在村（社区）",
                    trigger: "blur"
                  }],
                },
                {
                  label: "所在园区（开发区）",
                  prop: "szyq",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入所在园区（开发区）",
                    trigger: "blur"
                  }],
                },
                {
                  label: "工商注册地址",
                  prop: "gszcdz",
                  align: "center",
                  span: 24,
                  rules: [{
                    required: true,
                    message: "请输入工商注册地址",
                    trigger: "blur"
                  }],
                },
                {
                  label: "生产经营地址",
                  prop: "scjydz",
                  align: "center",
                  span: 24,
                  rules: [{
                    required: true,
                    message: "请输入生产经营地址",
                    trigger: "blur"
                  }],
                },
                {
                  label: "邮政编码",
                  prop: "yzbm",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入邮政编码",
                    trigger: "blur"
                  }],
                },
                {
                  label: "成立日期",
                  prop: "clrq",
                  align: "center",
                  type: "date",
                  format: "yyyy-MM-dd",
                  valueFormat: "yyyy-MM-dd",
                  rules: [{
                    required: true,
                    message: "请输入成立日期",
                    trigger: "click"
                  }]
                },
                {
                  label: "法人代表",
                  prop: "fddbr",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入法人代表",
                    trigger: "blur"
                  }],
                },
                {
                  label: "企业固定电话",
                  prop: "qygddh",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入企业固定电话",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全值班电话",
                  prop: "aqzbdh",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入安全值班电话",
                    trigger: "blur"
                  }],
                },
                {
                  label: "电子邮箱",
                  prop: "dzyx",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入电子邮箱",
                    trigger: "blur"
                  }],
                },
                {
                  label: "联系QQ号",
                  prop: "lxqqh",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入联系QQ号",
                    trigger: "blur"
                  }],
                },
                {
                  label: "单位传真",
                  prop: "dwcz",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入单位传真",
                    trigger: "blur"
                  }],
                },
                {
                  label: "官方网站地址",
                  prop: "gfwzdz",
                  align: "center",
                  span: 24,
                  rules: [{
                    required: false,
                    message: "请输入官方网站地址",
                    trigger: "blur"
                  }],
                },
                {
                  label: "主要负责人",
                  prop: "zyfzr",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入主要负责人",
                    trigger: "blur"
                  }],
                },
                {
                  label: "主要负责人固定电话",
                  prop: "zyfzrgddh",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入主要负责人固定电话",
                    trigger: "blur"
                  }],
                },
                {
                  label: "主要负责人移动电话",
                  prop: "zyfzryddh",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入主要负责人移动电话",
                    trigger: "blur"
                  }],
                },
                {
                  label: "主要负责人电子邮箱",
                  prop: "zyfzrdzyx",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入主要负责人电子邮箱",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全负责人",
                  prop: "aqfzr",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全负责人",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全负责人固定电话",
                  prop: "aqfzrgddh",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全负责人",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全负责人移动电话",
                  prop: "aqfzryddh",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全负责人",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全负责人电子邮箱",
                  prop: "aqfzrdzyx",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全负责人",
                    trigger: "blur"
                  }],
                },
                {
                  label: "经济类型大类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_jjlxdl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "jjlxdl",
                  rules: [{
                    required: true,
                    message: "请选择经济类型大类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "经济类型小类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_jjlxxl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "jjlxxl",
                  rules: [{
                    required: true,
                    message: "请选择经济类型小类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "行业类别门类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_hylbml",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "hylbml",
                  rules: [{
                    required: true,
                    message: "请选择行业类别门类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "行业类别大类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_hylbdl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "hylbdl",
                  rules: [{
                    required: true,
                    message: "请选择行业类别大类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "行业类别中类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_hylbzl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "hylbzl",
                  rules: [{
                    required: true,
                    message: "请选择行业类别中类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "行业类别小类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_hylbxl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "hylbxl",
                  rules: [{
                    required: true,
                    message: "请选择行业类别小类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "行业监管大类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_hyjgdl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "hyjgdl",
                  rules: [{
                    required: true,
                    message: "请选择行业监管大类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "行业监管小类",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_hyjgxl",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "hyjgxl",
                  rules: [{
                    required: true,
                    message: "请选择行业监管小类",
                    trigger: "blur"
                  }]
                },
                {
                  label: "专项治理类别",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_zxzllb",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "zxzllb",
                  rules: [{
                    required: true,
                    message: "请选择专项治理类别",
                    trigger: "blur"
                  }]
                },
                {
                  label: "是否为国有企业",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_yesno",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  dataType: "number",
                  slot: true,
                  prop: "sfwgyqy",
                  rules: [{
                    required: true,
                    message: "请选择是否为国有企业",
                    trigger: "blur"
                  }]
                },
                {
                  label: "隶属关系",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_lsgx",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "lsgx",
                  rules: [{
                    required: true,
                    message: "请选择隶属关系",
                    trigger: "blur"
                  }]
                },
                {
                  label: "经营范围",
                  prop: "jyfw",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入经营范围",
                    trigger: "blur"
                  }],
                },
                {
                  label: "经营状态",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_jyzt",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "jyzt",
                  rules: [{
                    required: true,
                    message: "请选择经营状态",
                    trigger: "blur"
                  }]
                },
                {
                  label: "注册资金（万元）",
                  prop: "zczj",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入注册资金（万元）",
                    trigger: "blur"
                  }],
                },
                {
                  label: "占地面试",
                  prop: "zdmj",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入占地面试",
                    trigger: "blur"
                  }],
                },
                {
                  label: "从业人员数量",
                  prop: "cyrysl",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入从业人员数量",
                    trigger: "blur"
                  }],
                },
                {
                  label: "特种作业人员数量",
                  prop: "tzzyrysl",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入特种作业人员数量",
                    trigger: "blur"
                  }],
                },
                {
                  label: "专职安全生产管理人员数量",
                  prop: "zzaqscglry",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入专职安全生产管理人员数量",
                    trigger: "blur"
                  }],
                },
                {
                  label: "兼职安全生产管理人员数量",
                  prop: "jzaqscglry",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入兼职安全生产管理人员数量",
                    trigger: "blur"
                  }],
                },
                {
                  label: "专职应急管理人员数量",
                  prop: "zzyjglry",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入专职应急管理人员数量",
                    trigger: "blur"
                  }],
                },
                {
                  label: "注册安全工程师人员数量",
                  prop: "zcaqgcsrs",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入注册安全工程师人员数量",
                    trigger: "blur"
                  }],
                },
                {
                  label: "是否有专门安全机构",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_yesno",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  dataType: "number",
                  slot: true,
                  prop: "sfyzmaqjg",
                  rules: [{
                    required: true,
                    message: "请选择是否有专门安全机构",
                    trigger: "blur"
                  }]
                },
                {
                  label: "安全管理机构名称",
                  prop: "aqgljgmc",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全管理机构名称",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全管理机构职责",
                  prop: "aqgljgzz",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全管理机构职责",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全管理机构成员数量",
                  prop: "aagljgcysl",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入安全管理机构职责",
                    trigger: "blur"
                  }],
                },
                {
                  label: "是否有专职安全人员",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_yesno",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  dataType: "number",
                  slot: true,
                  prop: "sfyzzaqry",
                  rules: [{
                    required: true,
                    message: "请选择是否有专职安全人员",
                    trigger: "blur"
                  }]
                },
                {
                  label: "规模情况",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_gmqk",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "gmqk",
                  rules: [{
                    required: true,
                    message: "请选择规模情况",
                    trigger: "blur"
                  }]
                },
                {
                  label: "企业规模",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_gygm",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "gygm",
                  rules: [{
                    required: true,
                    message: "请选择企业规模",
                    trigger: "blur"
                  }]
                },
                {
                  label: "是否有母公司",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_yesno",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  dataType: "number",
                  slot: true,
                  prop: "sfymgs",
                  rules: [{
                    required: true,
                    message: "请选择是否有母公司",
                    trigger: "blur"
                  }]
                },
                {
                  label: "母公司名称",
                  prop: "mgsmc",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入母公司名称",
                    trigger: "blur"
                  }],
                },
                {
                  label: "集团公司名称",
                  prop: "jtgsmc",
                  align: "center",
                  rules: [{
                    required: false,
                    message: "请输入集团公司名称",
                    trigger: "blur"
                  }],
                },
                {
                  label: "安全标准化等级",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_bzhdj",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "bzhdj",
                  rules: [{
                    required: true,
                    message: "请选择安全标准化等级",
                    trigger: "blur"
                  }]
                },
                {
                  label: "标准化证书有效期起始日期",
                  prop: "bzhzsyxqqsrq",
                  align: "center",
                  type: "date",
                  format: "yyyy-MM-dd",
                  valueFormat: "yyyy-MM-dd",
                  rules: [{
                    required: true,
                    message: "请输入标准化证书有效期起始日期",
                    trigger: "click"
                  }]
                },
                {
                  label: "标准化证书有效期终止日期",
                  prop: "bzhzsyxqzzrq",
                  align: "center",
                  type: "date",
                  format: "yyyy-MM-dd",
                  valueFormat: "yyyy-MM-dd",
                  rules: [{
                    required: true,
                    message: "请输入标准化证书有效期终止日期",
                    trigger: "click"
                  }]
                },
                {
                  label: "安全监管等级",
                  prop: "aqjgdj",
                  align: "center",
                  rules: [{
                    required: true,
                    message: "请输入安全监管等级",
                    trigger: "blur"
                  }],
                },
                {
                  label: "是否存在重大危险源",
                  type: "select",
                  align: "center",
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_yesno",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  dataType: "number",
                  slot: true,
                  prop: "sfczzdwxy",
                  rules: [{
                    required: true,
                    message: "请选择是否存在重大危险源",
                    trigger: "blur"
                  }]
                },
                {
                  label: "重大危险源最高等级",
                  type: "select",
                  align: "center",
                  span:12,
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=deptInfo_zdwxyzgdj",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  slot: true,
                  prop: "zdwxyzgdj",
                  rules: [{
                    required: true,
                    message: "请选择重大危险源最高等级",
                    trigger: "blur"
                  }]
                },
                {
                  label: '企业平面图',
                  prop: 'qypmt',
                  type: 'upload',
                  loadText: '图片上传中，请稍等',
                  multiple: true,
                  span: 24,
                  propsHttp: {
                    res: "data"
                  },
                  tip: '只能上传jpg/png文件，且不超过1M',
                  action: '/api/deptInfoManage/bladeDeptInfo/upLoadImg'
                },
                {
                  label: '企业营业执照',
                  prop: 'qyyyzz',
                  type: 'upload',
                  loadText: '图片上传中，请稍等',
                  multiple: true,
                  span: 24,
                  propsHttp: {
                    res: 'data'
                  },
                  tip: '只能上传jpg/png文件，且不超过1M',
                  action: '/api/deptInfoManage/bladeDeptInfo/upLoadImg'
                },
                {
                  label: '企业大门照片',
                  prop: 'qyzp',
                  type: 'upload',
                  loadText: '图片上传中，请稍等',
                  multiple: true,
                  span: 24,
                  propsHttp: {
                    res: 'data'
                  },
                  tip: '只能上传jpg/png文件，且不超过1M',
                  action: '/api/deptInfoManage/bladeDeptInfo/upLoadImg'
                },
                {
                  label: '',
                  prop: 'deptMap',
                  span: 24,
                  hide: true,
                  formslot: true,
                },
                {
                  label: "经度",
                  prop: "jd",
                  align: "center",
                  span:12,
                  rules: [{
                    required: true,
                    message: "请输入经度",
                    trigger: "blur"
                  }],
                },
                {
                  label: "纬度",
                  prop: "wd",
                  align: "center",
                  span:12,
                  rules: [{
                    required: true,
                    message: "请输入纬度",
                    trigger: "blur"
                  }],
                },
                {
                  label: "备注",
                  prop: "bz",
                  align: "center",
                  type: "textarea",
                  span: 24,
                  minRows: 6,
                  hide: true,
                },
              ]
            }
          ]
        },
        data: [],
        mapPosition: {
          lng: 121.4472540000,
          lat: 31.3236200000
        },
        center: {
          lng: 121.4472540000,
          lat: 31.3236200000
        },

        zoom: 10,
        dragging: false,
        deptShowMap: true,
        searchWord: ""
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.dept_info_add, false),
          viewBtn: this.vaildData(this.permission.dept_info_view, false),
          delBtn: this.vaildData(this.permission.dept_info_delete, false),
          editBtn: this.vaildData(this.permission.dept_info_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    watch: {
      // 表单经度
      'form.jd' (val) {
        if(val) {
          this.mapPosition.lng = val / 1
        }
      },
      // 表单纬度
      'form.wd' (val) {
        if(val) {
          this.mapPosition.lat = val / 1
        }
      }
    },
    methods: {
      // 地图处理事件
      deptInfoHandler({BMap, map}) {
        let _this = this;
        map.addEventListener('click', function(e) {
          _this.form.jd = e.point.lng
          _this.form.wd = e.point.lat
        });
        _this.$nextTick(() => {
          document.getElementById('citySearch').addEventListener('click', function() {
            let localSearch = new BMap.LocalSearch(map)
            localSearch.setSearchCompleteCallback(searchResult => {
              let poi = searchResult.getPoi(0)
              if(!poi) {
                return _this.$message.warning('该地址不存在')
              } else {
                _this.center = {
                  lng: poi.point.lng,
                  lat: poi.point.lat
                }
                _this.form.jd = poi.point.lng
                _this.form.wd = poi.point.lat
              }
            });
            localSearch.search(_this.searchWord);
          });
        })
      },

      //删除已经上传的图片
      uploadDelete(row, column, path) {
        console.log(column, path);
        let url = row.url;
        if (url) {
          //let splitter = "/home/xuyuming/img/";
          let splitter = "E:\\home\\imgs\\";
          let split = url.split(splitter);
          let element = split[1];
          let pathUrl = element.split(".");
          let fileName = pathUrl[0];
          return new Promise((resolve, reject) => {
            this.$confirm(`是否确认删除名称为${fileName}的图片`, "提示", {
              confirmButtonText: "确 定",
              cancelButtonText: "取 消",
              type: "warning"
            }).then(() => {
              // 重点来了这里操作完以后一定一定要resolve出去，因为这样avue会将原来的数据给清除  如果不resolve，那么再添加图片的话  他会把得到的路径与之前的拼接成一个字符串用“，”分割
              this.axios.post(`/api/deptInfoManage/bladeDeptInfo/deleteImg?fileName=${element}`);
              //返回的是否成功状态，都无法使用，默认会返回成功！！
              resolve()
            }).catch(() => {
              // 这里也一定一定要reject，虽然不搞 看似好像没问题  保险起见还是给写上，毕竟我不想再爬坑了 哈哈哈
              reject();
              this.$message({
                type: 'info',
                message: '已取消删除'
              })
            })
          })
        }
      },
      uploadBefore(file, done, loading) {
        this.isFailed = false;
        var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
        const extension = testmsg === 'jpg'
        const extension2 = testmsg === 'png'
        if(!extension && !extension2) {
          this.$message.warning('请上传 .jpg,.png 标准格式文件!');
          loading()
        } else {
          // 如果你想修改file文件,由于上传的file是只读文件，必须复制新的file才可以修改名字，完后赋值到done函数里,如果不修改的话直接写done()即可
          // var newFile = new File([file], {type: file.type});
          // done(newFile)
          done()
        }
      },
      uploadError(error, column) {
        if(this.isFailed === true){
          this.$message.error('上传失败');
        }
        console.log(error, column)
      },
      uploadAfter(res, done, loading, column) {
        done();
        if(res.msg.indexOf("success") < 0){
          this.isFailed = true
        }
        if(this.isFailed === false) {
          this.$message.success('上传成功');
        }
        console.log(column);
        this.cancel();
      },
      //上传图片后进行点击预览
      uploadPreview(file, column, done) {
        /*getImage(file.url).then(response => {
          this.localPicUrl = response.data;
          this.localPicBox = true;
        });*/
        window.open(`/api/deptInfoManage/bladeDeptInfo/getImage?${this.website.tokenHeader}=${getToken()}&fileName=${file.name}`);
        //this.localPicUrl = "/api/deptInfoManage/bladeDeptInfo/getImage?${this.website.tokenHeader}=${getToken()}&url=${file.url}"
        done();
      },

      rowSave(row, done, loading) {
        for(let key in row) {
          if(key.indexOf("$") >= 0) {
            delete row[key];
          }
        }
        var qypmtArr = [];
        var qyyyzzArr = [];
        var qyzpArr = [];
        this.form.qypmt.forEach(item => {
          qypmtArr.push(item.value);
        });
        this.form.qyyyzz.forEach(item => {
          qyyyzzArr.push(item.value);
        });
        this.form.qyzp.forEach(item => {
          qyzpArr.push(item.value);
        });
        row.qypmt = qypmtArr.join(",");
        row.qyyyzz = qyyyzzArr.join(",");
        row.qyzp = qyzpArr.join(",");
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          window.console.log(error);
          loading();
        });
      },
      rowUpdate(row, index, done, loading) {
        for(let key in row) {
          if(key.indexOf("$") >= 0) {
            delete row[key];
          }
        }
        if(row.qypmt instanceof Array){
          var qypmtArr = [];
          this.form.qypmt.forEach(item => {
            qypmtArr.push(item.value);
          });
          row.qypmt = qypmtArr.join(",");
        }
        if(row.qyyyzz instanceof Array){
          var qyyyzzArr = [];
          this.form.qyyyzz.forEach(item => {
            qyyyzzArr.push(item.value);
          });
          row.qyyyzz = qyyyzzArr.join(",");
        }
        if(row.qyzp instanceof Array){
          var qyzpArr = [];
          this.form.qyzp.forEach(item => {
            qyzpArr.push(item.value);
          });
          row.qyzp = qyzpArr.join(",");
        }
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          window.console.log(error);
          loading();
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDeptInfo(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        const {releaseTimeRange} = params;
        let values = {
          ...params,
        };
        if (releaseTimeRange) {
          values = {
            ...params,
            releaseTime_datege: releaseTimeRange[0],
            releaseTime_datelt: releaseTimeRange[1],
          };
          values.releaseTimeRange = null;
          this.query.releaseTimeRange = null;
        }
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(values, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style lang="scss" scpoed>
  .avue-crud__dialog {
    .el-dialog__body {
      .el-form-item__label {
        width: 130px !important;
      }

      .avue-form__row {
        .el-form-item__content {
          margin-left: 130px !important;
        }
      }
    }
  }

  .map {
    width: 100%;
    height: 500px;
  }

  .el-image {
    width: 100%;
    height: 100%;
  }
</style>
